﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.peddlerUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.geom.*;
    import org.aswing.*;
    import Classes.*;
    import org.aswing.geom.*;
    import Display.*;
    import Display.MarketUI.*;
    import GameMode.*;
    import Modules.peddler.*;
    import Display.peddlerUI.peddlerMarketUI.data.*;
    import Display.aswingui.*;

    public class PeddlerCell extends DataItemCell {

        private var m_peddlerToolTip:PeddlerWingToolTip;
        private var m_showTip:Boolean = true;
        private var m_initialized:Boolean = false;
        protected var m_slotOffset:int;
        private var m_itemIconPane:JPanel;

        public function PeddlerCell(_arg1:LayoutManager=null, _arg2:IntDimension=null, _arg3:int=2){
            super(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, 0, SoftBoxLayout.CENTER));
            if (_arg2){
            } else {
                _arg2 = new IntDimension(Catalog.CARD_WIDTH, Catalog.CARD_HEIGHT);
            };
            this.m_slotOffset = _arg3;
            setPreferredSize(_arg2);
        }
        override protected function initializeCell():void{
            this.createCell();
            this.createEventListener();
        }
        protected function createCell():void{
            var _local1:JPanel;
            var _local2:AssetPane;
            var _local3:AssetPane;
            if (this.m_initialized == false){
                _local1 = ASwingHelper.makeSoftBoxJPanelVertical(AsWingConstants.CENTER);
                this.m_itemIconPane = ASwingHelper.makeSoftBoxJPanelVertical();
                _local2 = new AssetPane(m_itemIcon);
                ASwingHelper.prepare(_local2);
                this.m_itemIconPane.append(_local2);
                ASwingHelper.prepare(this.m_itemIconPane);
                _local1.appendAll(ASwingHelper.verticalStrut(6), this.m_itemIconPane);
                ASwingHelper.prepare(_local1);
                this.append(_local1);
                ASwingHelper.prepare(this);
                this.m_initialized = true;
            } else {
                this.m_itemIconPane.removeAll();
                _local3 = new AssetPane(m_itemIcon);
                ASwingHelper.prepare(_local3);
                this.m_itemIconPane.append(_local3);
                ASwingHelper.prepare(this.m_itemIconPane);
            };
        }
        override public function setCellValue(_arg1):void{
            m_item = _arg1;
            var _local2:String = Global.gameSettings.getImageByName(m_item.name, (m_item as PeddlerModel).status);
            m_loader = LoadingManager.load(_local2, onIconLoad, LoadingManager.PRIORITY_HIGH);
        }
        public function invalidateData():void{
            if (this.m_initialized){
                ASwingHelper.prepare(this);
            };
        }
        protected function createEventListener():void{
            if (this.hasEventListener(MouseEvent.MOUSE_OVER)){
                this.removeEventListener(MouseEvent.MOUSE_OVER, this.onMouseOver);
            };
            if (this.hasEventListener(MouseEvent.MOUSE_OUT)){
                this.removeEventListener(MouseEvent.MOUSE_OUT, this.onMouseOut);
            };
            if (this.hasEventListener(MouseEvent.CLICK)){
                this.removeEventListener(MouseEvent.CLICK, this.onClickPeddler);
            };
            this.addEventListener(MouseEvent.CLICK, this.onClickPeddler);
            this.addEventListener(MouseEvent.MOUSE_OVER, this.onMouseOver);
            this.addEventListener(MouseEvent.MOUSE_OUT, this.onMouseOut);
        }
        private function onClickPeddler(_arg1:MouseEvent):void{
            var _local2:String;
            var _local3:GMPlaceMapResource;
            PeddlerBar.getInstance().closePeddler();
            if ((m_item as PeddlerData).status == PeddlerModel.STATE_WORKING){
                UI.displayPopup(new PeddlerWaringDialog(ZLoc.t("Dialogs", "Warning_in_working")));
                return;
            };
            if ((m_item as PeddlerData).status == PeddlerModel.STATE_REST){
                UI.displayPopup(new PeddlerWaringDialog(ZLoc.t("Dialogs", "Warning_in_resting")));
                return;
            };
            _local2 = "";
            _local2 = Global.peddlerManager.canPlacePeddler(m_item.name);
            switch (_local2){
                case PeddlerGroupManager.HAS_PLACEE_PEDDLER:
                    StatsManager.count("peddler_feature", "peddler_place_warning_has_placed_peddler");
                    UI.displayPopup(new PeddlerWaringDialog(ZLoc.t("Dialogs", "Warning_has_placed_peddler")));
                    break;
                case PeddlerGroupManager.NO_GOODS_TO_PLACE_PEDDLER:
                    StatsManager.count("peddler_feature", "peddler_place_warning_not_enough_goods");
                    UI.displayPopup(new PeddlerWaringDialog(ZLoc.t("Dialogs", "Warning_not_enough_goods")));
                    break;
                case PeddlerGroupManager.NO_SPACE_TO_PLACE_PEDDLER:
                    StatsManager.count("peddler_feature", "peddler_place_warning_no_more_space");
                    UI.displayPopup(new PeddlerWaringDialog(ZLoc.t("Dialogs", "Warning_no_more_space")));
                    break;
                default:
                    Global.peddlerManager.selectPeddler = m_item;
                    _local3 = new GMPlaceMapResource(m_item.name, Peddler, false);
                    _local3.itemData = m_item;
                    Global.world.addGameMode(_local3);
                    PeddlerBar.getInstance().closePeddler();
            };
        }
        private function onMouseOver(_arg1:MouseEvent):void{
            if (this.m_showTip == false){
                return;
            };
            var _local2:Boolean;
            var _local3:Point = this.localToGlobal(new Point(0, 0));
            var _local4:Number = (_local3.x - 60);
            var _local5:Number = (_local3.y - 180);
            if (_local5 >= 0){
                _local2 = false;
                _local4 = (_local3.x - 60);
                _local5 = (_local3.y - 180);
            } else {
                _local2 = true;
                _local4 = (_local3.x - 50);
                _local5 = (_local3.y + 90);
            };
            if (this.m_peddlerToolTip == null){
                this.m_peddlerToolTip = new PeddlerWingToolTip(_local2);
                Global.stage.addChild(this.m_peddlerToolTip);
            };
            this.m_peddlerToolTip.visible = true;
            this.m_peddlerToolTip.x = _local4;
            this.m_peddlerToolTip.y = _local5;
            this.m_peddlerToolTip.setUpDataForToolTip(m_item);
        }
        private function onMouseOut(_arg1:MouseEvent):void{
            if (this.m_showTip == false){
                return;
            };
            if (((this.m_peddlerToolTip) && (Global.stage.contains(this.m_peddlerToolTip)))){
                Global.stage.removeChild(this.m_peddlerToolTip);
                this.m_peddlerToolTip = null;
            };
        }
        public function showToolTip(_arg1:Boolean):void{
            this.m_showTip = _arg1;
        }
        public function showStatus(_arg1:String):void{
            var _local2:String;
            if (((m_item) && (this.m_itemIcon))){
                _local2 = Global.gameSettings.getImageByName(m_item.name, _arg1);
                m_loader = LoadingManager.load(_local2, onIconLoad, LoadingManager.PRIORITY_HIGH);
            };
        }

    }
}//package Display.peddlerUI 
